/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Connexion.java
 *
 * Created on 3 mai 2010, 11:10:14
 */
package progestion;
import Client.Client;
import java.rmi.RemoteException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Anne-Charlotte
 */
public class Connexion extends javax.swing.JDialog {
    ProGestionView proGestView;

    /** Creates new form Connexion */
    public Connexion(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        this.proGestView=proGestView;
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel_seconnecter = new javax.swing.JLabel();
        jLabel_incrire = new javax.swing.JLabel();
        jLabel_loginconnexion = new javax.swing.JLabel();
        jLabel_passconnexion = new javax.swing.JLabel();
        jTextField_loginconect = new javax.swing.JTextField();
        jLabel_nom = new javax.swing.JLabel();
        jLabel_prenom = new javax.swing.JLabel();
        jLabel_logininscr = new javax.swing.JLabel();
        jLabel_passinscr = new javax.swing.JLabel();
        jTextField_nom = new javax.swing.JTextField();
        jTextField_prenom = new javax.swing.JTextField();
        jTextField_logininscr = new javax.swing.JTextField();
        jButton_connexion = new javax.swing.JButton();
        jButton_inscription = new javax.swing.JButton();
        jPasswordField_passconect = new javax.swing.JPasswordField();
        jPasswordField_passinscr = new javax.swing.JPasswordField();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setName("connexion"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(progestion.ProGestionApp.class).getContext().getResourceMap(Connexion.class);
        jLabel_seconnecter.setText(resourceMap.getString("jLabel_seconnecter.text")); // NOI18N
        jLabel_seconnecter.setName("jLabel_seconnecter"); // NOI18N

        jLabel_incrire.setText(resourceMap.getString("jLabel_incrire.text")); // NOI18N
        jLabel_incrire.setName("jLabel_incrire"); // NOI18N

        jLabel_loginconnexion.setText(resourceMap.getString("jLabel_loginconnexion.text")); // NOI18N
        jLabel_loginconnexion.setName("jLabel_loginconnexion"); // NOI18N

        jLabel_passconnexion.setText(resourceMap.getString("jLabel_passconnexion.text")); // NOI18N
        jLabel_passconnexion.setName("jLabel_passconnexion"); // NOI18N

        jTextField_loginconect.setText(resourceMap.getString("jTextField_loginconect.text")); // NOI18N
        jTextField_loginconect.setName("jTextField_loginconect"); // NOI18N
        jTextField_loginconect.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField_loginconectActionPerformed(evt);
            }
        });

        jLabel_nom.setText(resourceMap.getString("jLabel_nom.text")); // NOI18N
        jLabel_nom.setName("jLabel_nom"); // NOI18N

        jLabel_prenom.setText(resourceMap.getString("jLabel_prenom.text")); // NOI18N
        jLabel_prenom.setName("jLabel_prenom"); // NOI18N

        jLabel_logininscr.setText(resourceMap.getString("jLabel_logininscr.text")); // NOI18N
        jLabel_logininscr.setName("jLabel_logininscr"); // NOI18N

        jLabel_passinscr.setText(resourceMap.getString("jLabel_passinscr.text")); // NOI18N
        jLabel_passinscr.setName("jLabel_passinscr"); // NOI18N

        jTextField_nom.setText(resourceMap.getString("jTextField_nom.text")); // NOI18N
        jTextField_nom.setName("jTextField_nom"); // NOI18N
        jTextField_nom.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField_nomActionPerformed(evt);
            }
        });

        jTextField_prenom.setText(resourceMap.getString("jTextField_prenom.text")); // NOI18N
        jTextField_prenom.setName("jTextField_prenom"); // NOI18N
        jTextField_prenom.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField_prenomActionPerformed(evt);
            }
        });

        jTextField_logininscr.setText(resourceMap.getString("jTextField_logininscr.text")); // NOI18N
        jTextField_logininscr.setName("jTextField_logininscr"); // NOI18N
        jTextField_logininscr.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField_logininscrActionPerformed(evt);
            }
        });

        jButton_connexion.setText(resourceMap.getString("jButton_connexion.text")); // NOI18N
        jButton_connexion.setName("jButton_connexion"); // NOI18N
        jButton_connexion.setRequestFocusEnabled(false);
        jButton_connexion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_connexionActionPerformed(evt);
            }
        });

        jButton_inscription.setText(resourceMap.getString("jButton_inscription.text")); // NOI18N
        jButton_inscription.setName("jButton_inscription"); // NOI18N
        jButton_inscription.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_inscriptionActionPerformed(evt);
            }
        });

        jPasswordField_passconect.setText(resourceMap.getString("jPasswordField_passconect.text")); // NOI18N
        jPasswordField_passconect.setName("jPasswordField_passconect"); // NOI18N

        jPasswordField_passinscr.setText(resourceMap.getString("jPasswordField_passinscr.text")); // NOI18N
        jPasswordField_passinscr.setName("jPasswordField_passinscr"); // NOI18N

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jLabel_seconnecter)
                    .add(layout.createSequentialGroup()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jLabel_passconnexion)
                            .add(jLabel_loginconnexion))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                            .add(jPasswordField_passconect)
                            .add(jTextField_loginconect, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 85, Short.MAX_VALUE)))
                    .add(layout.createSequentialGroup()
                        .add(19, 19, 19)
                        .add(jButton_connexion)))
                .add(112, 112, 112)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(layout.createSequentialGroup()
                                .add(47, 47, 47)
                                .add(jLabel_incrire))
                            .add(layout.createSequentialGroup()
                                .add(jLabel_passinscr)
                                .add(18, 18, 18)
                                .add(jPasswordField_passinscr, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 131, Short.MAX_VALUE))
                            .add(layout.createSequentialGroup()
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(jLabel_nom)
                                    .add(jLabel_prenom)
                                    .add(jLabel_logininscr))
                                .add(45, 45, 45)
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(jTextField_logininscr, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 132, Short.MAX_VALUE)
                                    .add(jTextField_prenom, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 132, Short.MAX_VALUE)
                                    .add(jTextField_nom, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 132, Short.MAX_VALUE))))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED))
                    .add(layout.createSequentialGroup()
                        .add(71, 71, 71)
                        .add(jButton_inscription)))
                .add(46, 46, 46))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(55, 55, 55)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(layout.createSequentialGroup()
                        .add(jLabel_incrire)
                        .add(25, 25, 25)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                            .add(jLabel_nom)
                            .add(jTextField_nom, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(jLabel_prenom)
                            .add(jTextField_prenom, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(jLabel_logininscr)
                            .add(jTextField_logininscr, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(layout.createSequentialGroup()
                                .add(jPasswordField_passinscr, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .add(45, 45, 45)
                                .add(jButton_inscription))
                            .add(jLabel_passinscr)))
                    .add(layout.createSequentialGroup()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                            .add(layout.createSequentialGroup()
                                .add(jLabel_seconnecter)
                                .add(30, 30, 30)
                                .add(jLabel_loginconnexion))
                            .add(jTextField_loginconect, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .add(15, 15, 15)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(jLabel_passconnexion)
                            .add(jPasswordField_passconect, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .add(80, 80, 80)
                        .add(jButton_connexion)))
                .addContainerGap(40, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton_connexionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_connexionActionPerformed
        // TODO add your handling code herev
        Client client=new Client();
        String loginc = jTextField_loginconect.getText();
        String mdpc = jPasswordField_passconect.getSelectedText();
        try {
           if(client.connexion(loginc, mdpc)!=null){
               client.setUtilCourant(client.connexion(loginc, mdpc))  ;
               ProGestionApp.getApplication().afficheFP(client);
           }
           
        } catch (RemoteException ex) {
            Logger.getLogger(Connexion.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        


    }//GEN-LAST:event_jButton_connexionActionPerformed

    private void jButton_inscriptionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_inscriptionActionPerformed
        // TODO add your handling code here:
        Client client = new Client();
        String nom = jTextField_nom.getText();
        String prenom = jTextField_prenom.getText();
        String logini = jTextField_logininscr.getText();
        String mdpi = jPasswordField_passinscr.getSelectedText();
        try {
            client.creerCompte(logini, mdpi, nom, prenom);
        } catch (RemoteException ex) {
            Logger.getLogger(Connexion.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_jButton_inscriptionActionPerformed

    private void jTextField_nomActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField_nomActionPerformed

        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField_nomActionPerformed

    private void jTextField_prenomActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField_prenomActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField_prenomActionPerformed

    private void jTextField_logininscrActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField_logininscrActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField_logininscrActionPerformed

    private void jTextField_loginconectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField_loginconectActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField_loginconectActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                Connexion dialog = new Connexion(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton_connexion;
    private javax.swing.JButton jButton_inscription;
    private javax.swing.JLabel jLabel_incrire;
    private javax.swing.JLabel jLabel_loginconnexion;
    private javax.swing.JLabel jLabel_logininscr;
    private javax.swing.JLabel jLabel_nom;
    private javax.swing.JLabel jLabel_passconnexion;
    private javax.swing.JLabel jLabel_passinscr;
    private javax.swing.JLabel jLabel_prenom;
    private javax.swing.JLabel jLabel_seconnecter;
    private javax.swing.JPasswordField jPasswordField_passconect;
    private javax.swing.JPasswordField jPasswordField_passinscr;
    private javax.swing.JTextField jTextField_loginconect;
    private javax.swing.JTextField jTextField_logininscr;
    private javax.swing.JTextField jTextField_nom;
    private javax.swing.JTextField jTextField_prenom;
    // End of variables declaration//GEN-END:variables

}
